package com.wkbb.basic.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.wkbb.basic.model.UserInfo;
import com.wkbb.basic.service.DataChangeService;
import com.wkbb.basic.smartschool.SSHttpClientUtil;
import com.wkbb.basic.smartschool.bean.DepartInfoDto;
import com.wkbb.basic.smartschool.bean.SSUserInfoDto;
import com.wkbb.basic.smartschool.bean.UserListBean;
import com.wkbb.basic.smartschool.bean.WitCampusResult;
import com.wkbb.common.base.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dengjingyuan
 * @date 2019-09-19 16:58
 */
@Slf4j
@Service
public class DataChangeSerImpl extends BaseServiceImpl<UserInfo> implements DataChangeService {


    @Override
    public void getWitOrganizationList(String objectId) {
         WitCampusResult<List<DepartInfoDto>> departList = SSHttpClientUtil.getDepartList(objectId, "1");
        log.info("**********开始获取当前学校的所有组织**********");
        if (SSHttpClientUtil.CODE.equals(departList.getCode())) {
            log.info("**********获取当前学校的所有组织成功**********");
            System.out.println(departList.getData());
            List<DepartInfoDto> departInfoDtoList=departList.getData();
            for(DepartInfoDto departInfoDtoInfo:departInfoDtoList){

            }
         }
        System.out.println(departList);
    }

    @Override
    public void getWitOrganizationInfo(String objectId) {
        WitCampusResult<List<DepartInfoDto>> departList = SSHttpClientUtil.getDepartInfo(objectId, "m86wLwI2958done");
        log.info("**********开始获取当前学校的组织信息**********");
        if (SSHttpClientUtil.CODE.equals(departList.getCode())) {
            log.info("**********获取当前学校的组织信息成功**********");
            System.out.println(departList.getData());
            List<DepartInfoDto> departInfoDtoList=departList.getData();
            for(DepartInfoDto departInfoDtoInfo:departInfoDtoList){

            }
        }
        System.out.println(departList);
    }

    @Override
    public void getWitSchoolInfo(String objectId) {
        String result=SSHttpClientUtil.getObjectInfo(objectId);
        if(SSHttpClientUtil.CODE.equals(JSONObject.parseObject(result).get("code"))){
            System.out.println(JSONObject.parseObject(result).get("data").toString());
            Short eduType=new Short(JSONObject.parseObject(JSONObject.parseObject(result).get("data").toString()).get("edu_type")+"");
            //學校類型:（1：本科 3：高职；4：中学；5：中职；8：小学；9：幼儿园；10：其他）
            System.out.println(eduType);
        }
    }

    @Override
    public void getWitUserInfoList(String objectId,Short userType,Short level,String departId){
         WitCampusResult<UserListBean> userListBeanWitCampusResult = SSHttpClientUtil.searchUser(objectId, userType.toString(), level.toString(), departId, null, null, null);
        if(SSHttpClientUtil.CODE.equals(userListBeanWitCampusResult.getCode())){
            System.out.println(userListBeanWitCampusResult);
        }
    }

    @Override
    public void getWitUserInfo(String objectId,String userid){
        WitCampusResult<SSUserInfoDto> userInfo= SSHttpClientUtil.getUserInfo(objectId,userid);
        if (SSHttpClientUtil.CODE.equals(userInfo.getCode())) {
            System.out.println(userInfo.getData());
        }
    }
}
